<template>
    <div>
        病房号：
        <input type="text" v-model="fan.name" >
        科室:  
        <select v-model="fan.id">
                        <option value="">请选择</option>
                        <option :value="o.kid" v-for="o in Ken">{{ o.kName }}</option>
                    </select>
        <input type="button" value="查询" @click="Show" >
        <table>
            <thead>
                <tr>
                    <td>病房号</td>
                    <td>科室</td>
                    <td>总床数</td>
                    <td>状态</td>
                    <td>空床</td>
                    <td>时间</td>
                    <td>功能</td>
                </tr>

                <tr v-for="o in info"  >
                    <td>{{ o.gName }}</td>
                    <td>{{ o.kName }}</td>
                    <td>{{ o.count }}</td>
                    <td>{{ o.state==1?"启用":"维修" }}</td>
                    <td>{{ o.kNum }}</td>
                    <td>{{ moment(o.gDate).format("yyyy-MM-DD") }}</td>
                    <td><input type="button" v-if="o.state==0" value="启用" @click="Update(o.gid,1)" >
                        <input type="button" v-if="o.state==1" value="维修" @click="Update(o.gid,0)" ></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { onMounted, ref } from 'vue';

onMounted(()=>{
    List();
    Show();
})

let Ken:any=ref([]);

const List=()=>{
    axios({
        url:"https://localhost:7030/api/User/ListK",
        method:'get',
    })

    .then((res)=>{
        console.log(res);
        Ken.value=res.data;
    })
}

let fan:any=ref({
    name:'',
    id:''
});
let info:any=ref([]);

const Show=()=>{
    axios({
        url:"https://localhost:7030/api/User/ShowG",
        method:'post',
        params:fan.value
    })

    .then((res)=>{
        console.log(res);
        info.value=res.data;
    })
}

const Update=(gid:any,state:any)=>{
    let f=confirm("要修改吗");
    if(f)
{
    axios({
        url:"https://localhost:7030/api/User/UpDatG",
        method:'post',
        params:{
            id:gid,
            state:state
        }
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0)
    {
        alert("修改成功");
        Show();
    }
    } )
}
    
}



</script>

<style scoped>

</style>